import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/supplier/model/supplier_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/utils.dart';
import 'package:tender_flutter/widgets/net_image.dart';

class SupplierListCell extends StatelessWidget {
  const SupplierListCell({Key key, this.data, this.onTap}) : super(key: key);

  final SupplierList data;
  final GestureTapCallback onTap;

  @override
  Widget build(BuildContext context) {
    return _initCell();
  }

  Widget _initCell() {
    return GestureDetector(
        onTap: onTap,
        child: Container(
          margin: EdgeInsets.only(
              left: ScreenAdapter.width(30), right: ScreenAdapter.width(30)),
          width: double.infinity,
          decoration: BoxDecoration(
              color: ThemeColors.colorWhite,
              borderRadius: BorderRadius.circular(ScreenAdapter.width(14))),
          child: Stack(
            children: <Widget>[
              Row(
                children: <Widget>[
                  _getImageView(),
                  Expanded(
                      child: Container(
                    margin: EdgeInsets.only(
                        top: ScreenAdapter.height(15),
                        bottom: ScreenAdapter.height(15)),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text(
                          _getTitle(),
                          style: TextStyle(
                              color: ThemeColors.colorType6,
                              fontSize: ScreenAdapter.sp(30),
                              fontWeight: FontWeight.bold),
                        ),
                        SizedBox(height: ScreenAdapter.height(4)),
                        Text(
                          _getDes(),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              color: ThemeColors.colorType14,
                              fontSize: ScreenAdapter.sp(26)),
                        ),
                        SizedBox(height: ScreenAdapter.height(8)),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Container(
                                padding: EdgeInsets.only(
                                    left: ScreenAdapter.width(15),
                                    right: ScreenAdapter.width(15),
                                    top: ScreenAdapter.width(6),
                                    bottom: ScreenAdapter.width(6)),
                                child: Text(data.area ?? "",
                                    style: TextStyle(
                                        color: ThemeColors.colorType40,
                                        fontSize: ScreenAdapter.sp(24))),
                                decoration: BoxDecoration(
                                    color: ThemeColors.colorType20,
                                    borderRadius:
                                        new BorderRadius.circular(3))),
                            // Container(
                            //     margin: EdgeInsets.only(
                            //         right: ScreenAdapter.width(30)),
                            //     child: GestureDetector(
                            //       onTap: () {
                            //         launch("tel:" + data.phone ?? "");
                            //       },
                            //       child: Image.asset(
                            //         RPath.imgPath + "icon_call_tel.png",
                            //         width: ScreenAdapter.width(43),
                            //         height: ScreenAdapter.width(43),
                            //       ),
                            //     ))
                          ],
                        )
                      ],
                    ),
                  ))
                ],
              ),
              // Container(
              //     alignment: Alignment.topRight,
              //     child: Image.asset(
              //       RPath.imgPath + "icon_top.png",
              //       width: ScreenAdapter.width(80),
              //       height: ScreenAdapter.width(80),
              //     ))
            ],
          ),
        ));
  }

  /// 获取头像
  Widget _getImageView() {
    if (data.type == AppConstant.SUPPLIER_PERSION) {
      /// 个人
      return Container(
        width: ScreenAdapter.width(132),
        height: ScreenAdapter.width(132),
        margin: EdgeInsets.only(
            left: ScreenAdapter.width(30), right: ScreenAdapter.width(18)),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: ThemeColors.colorType6,
            borderRadius: BorderRadius.circular(ScreenAdapter.width(14))),
        child: Text(!isEmpty(data.title) ? data.title.substring(0, 1) : "人",
            style: TextStyle(
                color: ThemeColors.colorWhite,
                fontSize: ScreenAdapter.sp(60),
                fontWeight: FontWeight.bold)),
      );
    } else {
      /// 企业供应商
      bool isPortrait = data.companyLogo != null && data.companyLogo.isNotEmpty;
      return Container(
        width: ScreenAdapter.width(132),
        height: ScreenAdapter.width(132),
        margin: EdgeInsets.only(
            left: ScreenAdapter.width(30), right: ScreenAdapter.width(18)),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: isPortrait ? ThemeColors.colorWhite : ThemeColors.colorType6,
            borderRadius: BorderRadius.circular(ScreenAdapter.width(14))),
        child: isPortrait
            ? MyNetImage(
                url: data.companyLogo ?? "",
                radius: BorderRadius.circular(ScreenAdapter.width(14)),
              )
            : Text("企",
                style: TextStyle(
                    color: ThemeColors.colorWhite,
                    fontSize: ScreenAdapter.sp(60),
                    fontWeight: FontWeight.bold)),
      );
    }
  }

  /// 标题
  String _getTitle() {
    return !isEmpty(data.title) ? data.title : "-";
  }

  /// 描述
  String _getDes() {
    if (data.type == AppConstant.SUPPLIER_PERSION) {
      /// 个人
      return !isEmpty(data.companyName) ? data.companyName : "暂无说明";
    } else {
      return !isEmpty(data.remark) ? data.remark : "暂无说明";
    }
  }
}
